package de.fh.ffm;

import java.util.HashSet;
import java.util.Set;

/**
 * Abstract Base class implementing the Subject of the Observer Pattern
 * 
 * @see Subject
 * @author seiwe
 */
public abstract class AbstractSubject implements Subject {

	private Set<Observer> observers = new HashSet<Observer>();

	/** {@inheritDoc} */
	public void addObserver ( Observer o ) {
		observers.add(o);
	}

	/** {@inheritDoc} */
	public void removeObserver ( Observer o ) {
		observers.remove(o);
	}

	/** {@inheritDoc} */
	public void notifyObservers () {
		for ( Observer o : observers ) {
			o.update(this);
		}
	}

}
